package oom;

public class JavaVMStackOOM {
	
	private int stackLength = 1;
	
	public void stackLeak(){
		stackLength++;
		stackLeak();
	}

	public static void main(String[] args) throws Throwable {
		JavaVMStackOOM oom = new JavaVMStackOOM();
		
		//test case1
//		try{
//			oom.stackLeak();
//		}catch (Throwable e) {
//			System.out.println("stack length " + oom.stackLength);
//			throw e;
//		}	
		
		//test case2
		oom.stackLeakByThread();
	}
	
	
	
	public void doing(){
		System.out.println(Thread.currentThread());
		while(true){}
	}
	
	public void stackLeakByThread(){
		while (true) {
			Thread thread = new Thread(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					doing();
				}
			});
			thread.start();
			
		}
				
	}
}
